<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Specify application credentials</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.zookeeper.html">« Zookeeper</a></li>
      <li style="float: right;"><a href="zookeeper.close.html">Zookeeper::close »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.zookeeper.html">Zookeeper</a></li>
    <li>Specify application credentials</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="zookeeper.addauth" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Zookeeper::addAuth</h1>
  <p class="verinfo">(PECL zookeeper &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Zookeeper::addAuth</span> &mdash; <span class="dc-title">Specify application credentials</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-zookeeper.addauth-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>Zookeeper::addAuth</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$scheme</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$cert</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$completion_cb</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   The application calls this function to specify its credentials for purposes of authentication. The server will use the security provider specified by the scheme parameter to authenticate the client connection. If the authentication request has failed:
    - the server connection is dropped.
    - the watcher is called with the ZOO_AUTH_FAILED_STATE value as the state parameter.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-zookeeper.addauth-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">scheme</code></dt>

    <dd>

     <p class="para">
      The id of authentication scheme. Natively supported: &quot;digest&quot; password-based authentication
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">cert</code></dt>

    <dd>

     <p class="para">
      Application credentials. The actual value depends on the scheme.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">completion_cb</code></dt>

    <dd>

     <p class="para">
      The routine to invoke when the request completes. One of the following result codes may be passed into the completion callback:
      - ZOK operation completed successfully
      - ZAUTHFAILED authentication failed
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-zookeeper.addauth-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-zookeeper.addauth-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   This method emits PHP error/warning when parameters count or types are wrong or operation fails.
  </p>
  <div class="caution"><strong class="caution">警告</strong>
    <p class="para">
      Since version 0.3.0, this method emits <span class="classname"><a href="class.zookeeperexception.html" class="classname">ZookeeperException</a></span> and it&#039;s derivatives.
    </p>
  </div>
 </div>


 <div class="refsect1 examples" id="refsect1-zookeeper.addauth-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="zookeeper.addauth.example.basic">
   <p><strong>示例 #1 <span class="methodname"><strong>Zookeeper::addAuth()</strong></span> example</strong></p>
   <div class="example-contents"><p>
     Add auth before requesting node value.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$zookeeper&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Zookeeper</span><span style="color: #007700">(</span><span style="color: #DD0000">'locahost:2181'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$path&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'/path/to/node'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'nodevalue'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$zookeeper</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$zookeeper</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addAuth</span><span style="color: #007700">(</span><span style="color: #DD0000">'digest'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'user0:passwd0'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$r&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$zookeeper</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$r</span><span style="color: #007700">)<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$r</span><span style="color: #007700">;<br />else<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'ERR'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
nodevalue
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-zookeeper.addauth-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="zookeeper.create.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::create()</a> - Create a node synchronously</span></li>
   <li class="member"><span class="methodname"><a href="zookeeper.setacl.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::setAcl()</a> - Sets the acl associated with a node synchronously</span></li>
   <li class="member"><span class="methodname"><a href="zookeeper.getacl.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::getAcl()</a> - Gets the acl associated with a node synchronously</span></li>
   <li class="member"><a href="class.zookeeper.html#zookeeper.class.constants.states" class="link">ZooKeeper States</a></li>
   <li class="member"><span class="classname"><a href="class.zookeeperexception.html" class="classname">ZookeeperException</a></span></li>
  </ul>
 </div>


</div></div></div></body></html>